Test Series - java script

Test Number 19/92

Q: What convenience does the following JavaScript code snippet provide?

let succ = function(x) x+1, yes = function() true, no = function() false;
A. Functional behaviour
B. Modular behaviour
C. No convenience
D. Shorthand expression
Solution: The functions defined in this way behave exactly like functions defined with curly braces and the return keyword. The above code makes the expression short and reduces the line of code.
Q: What is the code to be used to trim whitespaces?
A. let trimmed = (l.trim() for (l in lines));
B. let trimmed = (trim(l));
C. let trimmed = l.trim();
D. let trimmed = for(l in lines));
Solution: The various types of trim functions are trimLeft(), trimRight() and trim().can use the above code to trim whitespaces and filter out comments and blank lines.
Q: What will be the reaction when a catch clause has no conditionals?
A. Takes it to be 0
B. Takes it to be 1
C. Takes it to be true
D. Takes it to be false
Solution: The try and catch statement handles some or all of the errors that may occur in a block of code, while still running code. If a catch clause has no conditional, it behaves as if it has the conditional if true, and it is always triggered if no clause before it was triggered.
Q: When will the finally block be called?
A. When there is no exception
B. When the catch does not match
C. When there is exception
D. After try-catch execution
Solution: The try and catch statement handles some or all of the errors that may occur in a block of code, while still running code. A finally block is called after try-catch execution.
Q: What is the return type of typeof for standard JavaScript objects?
A. xml
B. object
C. dom
D. html
Solution: The typeof operator returns “object” for all standard JavaScript objects. It returns “object” for a null, “number” for NaN, “number” for Infinity, “object” for a “new Number(1)” and “object” for an array.
Q: Which method to use while working with XML fragments, instead of XML()?
A. XMLInterface()
B. XMLClass()
C. XMLList()
D. XMLArray()
Solution: An XML fragment is an XML document with no single top-level root element. When working with XML fragments, use XMLList() instead of XML().
Q: Which of the following is the descendant operator?
A. ..
B. 
C. *
D. @
Solution: While the . operator accesses direct children of the given node, the .. operator accesses all children no matter how deeply nested: The .. operator is the descendant operator; you can use it in place of the normal. member-access operator:
var names = pt..name;
Q: Which of the following is an example to perform the most common XML manipulations using the XML objects invocation?
A. insertChildBefore()
B. insertChildAfter()
C. appendChildAfter(…)
D. appendChildBefore(…)
Solution: E4X is designed so that you can perform most common XML manipulations using language syntax. E4X also defines methods you can invoke on XML objects. Here, for example, is the insertChildBefore() method:
pt.insertChildBefore(pt.element[1],Deuterium);
Q: What is the code required to delete all “weight” tags?
A. delete weight(pt).all;
B. delete pt.element[all];
C. delete pt;
D. delete pt..weight;
Solution: Delete is a keyword in javascript which is used for deleting objects ,pointers and variables. Removing attributes and tags is very easy with the standard delete operator :
delete pt..weight; //delete all  tags
Q: What will be the output of the following JavaScript code?

A. 10
B. 9.65
C. 9.6
D. 9.656
Solution: toFixed() method rounds off the number to specified number of decimal places. Since the argument is passed with 0 value therefore the output will be 10.

You Have Score    /10